package com.situ.temp;

import java.util.Scanner;

public class StudentManager {

    //main
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入学生数量：");
        int count = scanner.nextInt();
        Student[] array = new Student[count];
        for (int i = 0; i < array.length; i++) {
            //每遍历一次输入一个学生信息，封装成一个Student对象
            System.out.println("请输入学生id:");
            int id = scanner.nextInt();
            System.out.println("请输入学生名字：");
            String name = scanner.next();
            System.out.println("请输入年龄：");
            int age = scanner.nextInt();
            System.out.println("请输入班级名字：");
            String className = scanner.next();

            Student student = new Student(id, name, age, className);
            //把学生放到数组里面
            array[i] = student;
        }

        //打印所有输入的学生信息
        for (int i = 0; i < array.length; i++) {
            //Student student = array[i];
            //System.out.println(student);
            System.out.println(array[i]);
        }

        while (true) {
            //搜索功能
            System.out.println("输入1根据id搜索");
            System.out.println("输入2根据name搜索");
            System.out.println("输入3根据age搜索");
            System.out.println("输入4根据className搜索");
            System.out.println("输入0 退出");
            int type = scanner.nextInt();
            if (type == 0) {
                System.out.println("退出搜索");
                break;
            }

            switch (type) {
                case 1:
                    break;
                case 2:
                    System.out.println("请输入搜索的name:");
                    String name = scanner.next();
                    for (int i = 0; i < array.length; i++) {
                        Student student = array[i];
                        //String里面有个方法叫equals()可以判断两个字符串是不是相等
                        //相等返回true，不相等返回false
                        if (student.getName().equals(name)) {
                            System.out.println(student);
                        }
                    }
                    break;
                case 3:
                    System.out.println("请输入搜索的年龄:");
                    int age = scanner.nextInt();
                    for (int i = 0; i < array.length; i++) {
                        Student student = array[i];
                        if (student.getAge() == age) {
                            System.out.println(student);
                        }
                    }
                    break;
                case 4:
                    break;
            }
        }
    }
}
